package net.cyndeline.GUI.rendering

import net.cyndeline.scalarlib.entityComponent.miranda.{Entity, EntityListener}

/**
 * Prevents graphical representations from being rendered when the entity owning the representation has been
 * deleted. Subscribes to entity deletions inside the entity manager and clears the entity's entry in the graphical
 * storage object.
 */
class EntityDeletionListener(graphics: GraphicsContainer) extends EntityListener {

  // Doesn't need to do anything, entities have no graphical representations by default.
  def onCreate(entity: Entity): Unit = {}

  def onDelete(entity: Entity): Unit = {
    graphics.deleteGraphic(entity)
  }
}
